-----切换频道
ChannelUP = 1
RegisterKeyMapping('+nc', 'NextRadioChannel', 'keyboard', config.SwichKey)
RegisterCommand('+nc', function()
        --
    if ChannelUP > 100 then
        NewNoti("~r~最大频道数量.", true)
    end
    if exports.tokovoip_script:isPlayerInChannel(ChannelUP) == true then
    exports.tokovoip_script:removePlayerFromRadio(ChannelUP)
    Channel2 = ChannelUP + 1
    exports.tokovoip_script:addPlayerToRadio(Channel2, true)
    ChannelUP = Channel2
    print (ChannelUP)
    NewNoti("~y~切换到下一个频道.", true)
    SendNUIMessage({
        PayloadType	= {"Swich", "click"},
        Payload	= source
    }) 
    end
    --
    if exports.tokovoip_script:isPlayerInChannel(100) == true then
        exports.tokovoip_script:removePlayerFromRadio(100)
        Channel2 = 1
        exports.tokovoip_script:addPlayerToRadio(Channel2, true)
        ChannelUP = Channel2
        print (ChannelUP)
        NewNoti("~y~切换到第一个频道.", true)
        SendNUIMessage({
            PayloadType	= {"Swich", "click"},
            Payload	= source
        }) 
        end
end)

RegisterKeyMapping('+pc', 'PreviousRadioChannel', 'keyboard', config.SwichpcKey)
RegisterCommand('+pc', function()
        --
    if exports.tokovoip_script:isPlayerInChannel(1) == true then
        exports.tokovoip_script:removePlayerFromRadio(1)
        exports.tokovoip_script:addPlayerToRadio(100, true)
        ChannelUP = 100
        NewNoti("~r~切换到最后一个频道.", true)
        SendNUIMessage({
            PayloadType	= {"Swich", "click"},
            Payload	= source
    }) 
    end
    if exports.tokovoip_script:isPlayerInChannel(ChannelUP) == true then
        exports.tokovoip_script:removePlayerFromRadio(ChannelUP)
        ChannelDown = ChannelUP - 1
        exports.tokovoip_script:addPlayerToRadio(ChannelDown, true)
        ChannelUP = ChannelDown
        NewNoti("~y~切换到上一个频道.", true)
        SendNUIMessage({
            PayloadType	= {"Swich", "click"},
            Payload	= source
        }) 
        end
end)
RegisterKeyMapping('+TAC1', 'RadioTac1Channel', 'keyboard', config.SwichTAC1Key)
RegisterCommand('+TAC1', function()

    if exports.tokovoip_script:isPlayerInChannel(ChannelUP) == true then
        exports.tokovoip_script:removePlayerFromRadio(ChannelUP)
        exports.tokovoip_script:addPlayerToRadio(3, true)
        ChannelUP = 3
        NewNoti("~r~切换到TAC1频道.", true)
        SendNUIMessage({
            PayloadType	= {"Swich", "LocalSwich"},
            Payload	= source
        })
    end
    if exports.tokovoip_script:isPlayerInChannel(3) == true then
        ChannelUP = 3
        NewNoti("~g~已经在TAC1频道.", true)
        SendNUIMessage({
            PayloadType	= {"Swich", "LocalSwich"},
            Payload	= source
        })
    end
end)
RegisterKeyMapping('+PA', 'RadioPAChannel', 'keyboard', config.SwichPAKey)
RegisterCommand('+PA', function()
    if exports.tokovoip_script:isPlayerInChannel(ChannelUP) == true then
    exports.tokovoip_script:removePlayerFromRadio(ChannelUP)
    exports.tokovoip_script:addPlayerToRadio(6, true)
    ChannelUP = 6
    NewNoti("切换到学院频道.", true)
    SendNUIMessage({
        PayloadType	= {"Swich", "LocalSwich"},
        Payload	= source
    })
    end
    
    if exports.tokovoip_script:isPlayerInChannel(6) == true then
        ChannelUP = 6
        NewNoti("~g~你已经在学院频道.", true)
        SendNUIMessage({
            PayloadType	= {"Swich", "LocalSwich"},
            Payload	= source
        })
    end
end)
RegisterKeyMapping('+PD', 'RadioPDChannel', 'keyboard', config.SwichPDKey)
RegisterCommand('+PD', function()
    if exports.tokovoip_script:isPlayerInChannel(ChannelUP) == true then
        exports.tokovoip_script:removePlayerFromRadio(ChannelUP)
        exports.tokovoip_script:addPlayerToRadio(1, true)
        ChannelUP = 1
        NewNoti("切换到PD频道.", true)
        SendNUIMessage({
            PayloadType	= {"Swich", "LocalSwich"},
            Payload	= source
        })
    end
    if exports.tokovoip_script:isPlayerInChannel(1) == true then
        NewNoti("~g~你已经在PD频道.", true)
        SendNUIMessage({
            PayloadType	= {"Swich", "LocalSwich"},
            Payload	= source
        })
    end
end)
RegisterKeyMapping('+SD', 'RadioSDChannel', 'keyboard', config.SwichSDKey)
RegisterCommand('+SD', function()
    if exports.tokovoip_script:isPlayerInChannel(ChannelUP) == true then
        exports.tokovoip_script:removePlayerFromRadio(ChannelUP)
        exports.tokovoip_script:addPlayerToRadio(2, true)
        ChannelUP = 2
        NewNoti("切换到SD频道.", true)
        SendNUIMessage({
            PayloadType	= {"Swich", "LocalSwich"},
            Payload	= source
        })
    end
    if exports.tokovoip_script:isPlayerInChannel(2) == true then
        NewNoti("~g~你已经在SD频道.", true)
        SendNUIMessage({
            PayloadType	= {"Swich", "LocalSwich"},
            Payload	= source
        })
    end
end)
function NewNoti(Text, Flash)
    SetNotificationTextEntry("STRING")
    AddTextComponentString(Text)
    DrawNotification(Flash, true)
end
------------------紧急按钮---------------------------------
local Panic = {}
Panic.Cooling = 0
RegisterKeyMapping('+panic', 'Panic Button', 'keyboard', config.PanicKey)
RegisterCommand("+panic", function()
    if Panic.Cooling == 0 then
        local Officer = {}
        Officer.Ped = PlayerPedId()
        Officer.Name = GetPlayerName(PlayerId())
        Officer.Coords = GetEntityCoords(Officer.Ped)
        Officer.Location = {}
        Officer.Location.Street, Officer.Location.CrossStreet = GetStreetNameAtCoord(Officer.Coords.x, Officer.Coords.y, Officer.Coords.z)
        Officer.Location.Street = GetStreetNameFromHashKey(Officer.Location.Street)
        if Officer.Location.CrossStreet ~= 0 then
            Officer.Location.CrossStreet = GetStreetNameFromHashKey(Officer.Location.CrossStreet)
            Officer.Location = Officer.Location.Street .. " X " .. Officer.Location.CrossStreet
        else
            Officer.Location = Officer.Location.Street
        end

        TriggerServerEvent("Police-Panic:NewPanic", Officer)

        Panic.Cooling = config.Cooldown
    else
        NewNoti("~r~紧急按钮冷却中.", true)
    end
end)

-- 客户端事件
RegisterNetEvent("Pass-Alarm:Return:NewPanic")
AddEventHandler("Pass-Alarm:Return:NewPanic", function(source, Officer)
    if Officer.Ped == PlayerPedId() then
        SendNUIMessage({
            PayloadType	= {"Panic", "LocalPanic"},
            Payload	= source
        })
    else
        SendNUIMessage({
            PayloadType	= {"Panic", "ExternalPanic"},
            Payload	= source
        })
    end

    -- Only people tuned to the panic channel can see the message
    TriggerEvent("chat:addMessage", {
        color = {255, 0, 0},
        multiline = true,
        args = {config.Sender, config.Message .. " - " .. Officer.Name .. " (" .. source .. ") - " .. Officer.Location}
    })

    Citizen.CreateThread(function()
        local Blip = AddBlipForRadius(Officer.Coords.x, Officer.Coords.y, Officer.Coords.z, 100.0)

        SetBlipRoute(Blip, true)

        Citizen.CreateThread(function()
            while Blip do
                SetBlipRouteColour(Blip, 1)
                Citizen.Wait(150)
                SetBlipRouteColour(Blip, 6)
                Citizen.Wait(150)
                SetBlipRouteColour(Blip, 35)
                Citizen.Wait(150)
                SetBlipRouteColour(Blip, 6)
            end
        end)

        SetBlipAlpha(Blip, 60)
        SetBlipColour(Blip, 1)
        SetBlipFlashes(Blip, true)
        SetBlipFlashInterval(Blip, 200)

        Citizen.Wait(config.BlipTime * 1000)

        RemoveBlip(Blip)
        Blip = nil
    end)
end)
Citizen.CreateThread(function()
	while true do
		Citizen.Wait(0)

		if Panic.Cooling ~= 0 then
			Citizen.Wait(1000)
			Panic.Cooling = Panic.Cooling - 1
		end
	end
end)
-----调度提示---
RegisterKeyMapping('+dp', 'DP Button', 'keyboard', config.DPKey)
RegisterCommand('+dp', function()
    TriggerServerEvent("dispatch-Button:Newdispatch", Officer)
end)
RegisterNetEvent("Pass-Alarm:Return:Newdispatch")
AddEventHandler("Pass-Alarm:Return:Newdispatch", function(source, Officer)
        SendNUIMessage({
            PayloadType	= {"Dispatch", "dispatch"},
            Payload	= source
        })
end)